package com.neuedu.vuejsserver.domain;

import com.alibaba.fastjson.JSON;
import com.neuedu.entity.Dept;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目：      jweb
 * 类名:       PageDomain
 * 创建时间：  2023/11/29 13：37
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Page {

    private  Integer   pageNo = 1;
    private  Integer   size = 10;

    //数据
    private List data;

    //总页数
    private  Integer   pages;

    //总条数
    private  long   total;


    public static Page getInstatnce(int pageNo,List data,long total){
        int size = 10;
        return  getInstatnce(pageNo,size,data,total);
    }

    public static Page getInstatnce(int pageNo,int size , List data,long total){

        int pages = (int)(total % size == 0  ?total / size: total /size+1);
        return  new Page(pageNo,size,data,pages,total);
    }
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < 100; i++) {
            arrayList.add(new Dept());
        }
        Page page = Page.getInstatnce(1,arrayList , 100);

        String json = JSON.toJSONString(page);

        System.out.println("json = " + json);
    }


}
